<template>
	<div>
		<div style="box-shadow: 0 1px 8px 0 rgba(0, 0, 0, 0.1);height: 60px;line-height: 60px;">
			<div style="float: left; font-size: 30px; width: 60px; text-align: center; border-right: 2px solid #DCDDE0;">
				<i class="el-icon-search"></i>
			</div>
			<font color="#72767B" style="margin-left: 20px;">筛选查询</font>
			<div style="float: right; width: auto;">
				<font color="#72767B" style="margin-left: 20px;">模糊条件</font>
				<div style="float: right; margin-right: 30px;">
					<el-button type="primary" @click="vagueQuery()">查询</el-button>
				</div>
				<div style="float: right; width: auto;margin-right: 20px; margin-left: 20px;">
					<el-input v-model="categoryPage.queryCriteria.subclassName" placeholder="请输入分类名称进行查询"></el-input>
				</div>
			</div>
			<div style="float: right; width: auto; margin-right: 20px;">
				<font color="#72767B" style="margin-right: 20px;">大类</font>
				<el-select clearable size='mini' v-model="state" placeholder="大类查询" autocomplete="off">
				  <el-option v-for="item in stateList" :label="item.primaryCategoryName" :value ="item.primaryCategoryId"></el-option>
				</el-select>
			</div>
		</div>
		 
		<div style="box-shadow: 0 1px 8px 0 rgba(0, 0, 0, 0.1);height: 60px;line-height: 60px; margin-top: 20px;">
			<div style="float: left; font-size: 30px; width: 60px; text-align: center; border-right: 2px solid #DCDDE0;">
				<i class="el-icon-s-grid"></i>
			</div>
			<font color="#72767B" style="margin-left: 20px;">数据列表</font>
			
			<div style="float: right; margin-right: 30px;">
				<el-button type="info" :disabled="indexList.length ==0" @click="delCategory()">删除</el-button>
			</div>
			<div style="float: right; margin-right: 30px;">
				<el-button type="info" :disabled="indexList.length ==0" @click="modifyCategory()">修改</el-button>
			</div>
			<div style="float: right; margin-right: 30px;">
				<el-button type="info" @click="dialogFormVisible1 = true">新增</el-button>
			</div>
			
			<div style="box-shadow: 0 1px 8px 0 rgba(0, 0, 0, 0.1);margin-top: 4px;">
				<el-table height="600px" :data="allCategory" border style="width: 100%" @select="getCategory" :row-style="formStyle">
					<el-table-column align="center" type="selection" width="55"></el-table-column>
					<el-table-column align="center" prop="subclassNumber" label="编号" width="180"></el-table-column>
					<el-table-column align="center" prop="subclassName" label="分类名称" width="180"></el-table-column>
					<el-table-column align="center" prop="primaryCategoryName" label="所属大类" width="180"></el-table-column>
					<el-table-column align="center" prop="subclassLevel" label="级别" width="180"></el-table-column>
					<el-table-column align="center" prop="subclassUnit" label="单位" width="180"></el-table-column>
					<el-table-column align="center" prop="subclassOrder" label="排序" width="180"></el-table-column>
					<el-table-column align="center" :formatter="formatterShow" prop="subclassShow" label="显示" width="180"></el-table-column>
					<el-table-column align="center" label="操作">
						<template slot-scope="scope">
							<el-button @click="addType(scope.row.subclassId)" type="text" size="small">新增下级</el-button>
							<el-button @click="showType(scope.row.subclassId)" type="text" size="small">查看下级</el-button>
						</template>
					</el-table-column>
					
				</el-table>
			</div>
			<div style="text-align: center;">
				<el-pagination :page-count="pageCount" @current-change="changPage" 
				:current-page="categoryPage.indexPage"  background layout="prev, pager, next"></el-pagination>
			</div>
		</div>
		
		<!-- 修改弹出框 -->
		<el-dialog title="小类修改" :visible.sync="dialogFormVisible">
			<el-form :model="oneModel" :rules="oneModelRules" ref="oneModel" label-width="120px" class="demo-ruleForm">
				<el-form-item label="编号" prop="subclassNumber">
					<el-input readonly type="text" autosize v-model="oneModel.subclassNumber"></el-input>
				</el-form-item>
				<el-form-item label="名称" prop="subclassNumber">
					<el-input readonly type="text" autosize v-model="oneModel.subclassName"></el-input>
				</el-form-item>
				<el-form-item label="所属大类">
					<el-select clearable size='mini' v-model="state" placeholder="大类名称" autocomplete="off">
						<el-option v-for="item in stateList" :label="item.primaryCategoryName" :value ="item.primaryCategoryId"></el-option>
					</el-select>
				</el-form-item>
				
				<el-form-item label="排序" prop="primaryCategoryOrder">
					<el-input type="number" autosize v-model="oneModel.subclassOrder"></el-input>
				</el-form-item>
				
				<el-form-item label="级别" prop="subclassLevel">
					<el-input type="number" autosize v-model="oneModel.subclassLevel"></el-input>
				</el-form-item>
				
				<el-form-item label="单位" prop="subclassUnit">
					<el-input type="text" autosize v-model="oneModel.subclassUnit"></el-input>
				</el-form-item>
				
				<el-form-item label="图标上传" prop="primaryCategoryIcon">
				<el-upload class="upload-demo" action="http://localhost/primary-category/upload"
					:on-success="uploadSuccess" :file-list="fileList" list-type="picture">
					<el-button size="small" type="primary">点击上传</el-button>
					<div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
				</el-upload>
				</el-form-item>
				
				<el-form-item label="鉴定图定义">
					<div v-for="(image, index) in imageParamList">
						<div style="float: left;">
							<el-input v-model="image.appraisalImageName" placeholder="正面"></el-input>
						</div>
						<el-select clearable v-model="image.appraisalImageState" autocomplete="off">
							<el-option label="必选" value ="1"></el-option>
							<el-option label="可选" value ="0"></el-option>
						</el-select>
						<font size="3" class="del_font" @click="delImage(index)">删除</font>
					</div>
					<font size="3" class="del_font" @click="addImage()">新增</font>
				</el-form-item>
				
				<el-form-item label="分类描述" prop="subclassDesc">
					<el-input type="textarea" v-model="oneModel.subclassDesc"></el-input>
				</el-form-item>
				
				<el-form-item label="是否显示" prop="subclassShow">
					<el-radio v-model="radio" label="1">是</el-radio>
					<el-radio v-model="radio" label="0">否</el-radio>
				</el-form-item>
				
				<el-form-item>
					<el-button type="primary" @click="confirm('oneModel')">确认</el-button>
					<el-button type="primary" @click="cancel()">取消</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
		
		<el-dialog title="提示" :visible.sync="delVisible" width="30%">
		  <span>所选类有下级类别，删除将同时删除下级列表，是否确认删除</span>
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="delVisible = false">取 消</el-button>
		    <el-button type="primary" @click="deleteConfirm">确 定</el-button>
		  </span>
		</el-dialog>
		
		<!-- 新增弹出框 -->
		<el-dialog title="小类新增" :visible.sync="dialogFormVisible1">
			<el-form :model="addModel" :rules="oneModelRules" ref="addModel" label-width="120px" class="demo-ruleForm">
				
				<el-form-item label="小类名称" prop="subclassName">
					<el-input type="text" autosize v-model="addModel.subclassName"></el-input>
				</el-form-item>
				
				<el-form-item label="所属大类">
					<el-select clearable size='mini' v-model="state" placeholder="大类名称" autocomplete="off">
						<el-option v-for="item in stateList" :label="item.primaryCategoryName" :value ="item.primaryCategoryId"></el-option>
					</el-select>
				</el-form-item>
				
				<el-form-item label="排序" prop="primaryCategoryOrder">
					<el-input type="number" autosize v-model="addModel.subclassOrder"></el-input>
				</el-form-item>
				
				<el-form-item label="级别" prop="subclassLevel">
					<el-input type="number" autosize v-model="addModel.subclassLevel"></el-input>
				</el-form-item>
				
				<el-form-item label="单位" prop="subclassUnit">
					<el-input type="text" autosize v-model="addModel.subclassUnit"></el-input>
				</el-form-item>
				
				<el-form-item label="图标上传" prop="primaryCategoryIcon">
				<el-upload class="upload-demo" action="http://localhost/primary-category/upload"
					:on-success="uploadSuccess" :file-list="fileList" list-type="picture">
					<el-button size="small" type="primary">点击上传</el-button>
					<div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
				</el-upload>
				</el-form-item>
				
				<el-form-item label="鉴定图定义">
					<div v-for="(image, index) in imageParamList">
						<div style="float: left;">
							<el-input v-model="image.appraisalImageName" placeholder="正面"></el-input>
						</div>
						<el-select clearable v-model="image.appraisalImageState" autocomplete="off">
							<el-option label="必选" value ="1"></el-option>
							<el-option label="可选" value ="0"></el-option>
						</el-select>
						<font size="3" class="del_font" @click="delImage(index)">删除</font>
					</div>
					<font size="3" class="del_font" @click="addImage()">新增</font>
				</el-form-item>
				
				<el-form-item label="分类描述" prop="subclassDesc">
					<el-input type="textarea" v-model="addModel.subclassDesc"></el-input>
				</el-form-item>
				
				<el-form-item label="是否显示" prop="subclassShow">
					<el-radio v-model="radio" label="1">是</el-radio>
					<el-radio v-model="radio" label="0">否</el-radio>
				</el-form-item>
				
				<el-form-item>
					<el-button type="primary" @click="confirmAdd('oneModel')">确认</el-button>
					<el-button type="primary" @click="cancel()">取消</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
		
		
		<!-- 查看类别弹出框 -->
		<el-dialog title="查看类别" :visible.sync="typeFormShow" width="1500px">
			
			<div style="box-shadow: 0 1px 8px 0 rgba(0, 0, 0, 0.1);height: 60px;line-height: 60px;">
				<div style="float: left; font-size: 30px; width: 60px; text-align: center; border-right: 2px solid #DCDDE0;">
					<i class="el-icon-search"></i>
				</div>
				<font color="#72767B" style="margin-left: 20px;">筛选查询</font>
				<div style="float: right; width: auto;">
					<font color="#72767B" style="margin-left: 20px;">模糊条件</font>
					<div style="float: right; margin-right: 30px;">
						<el-button type="primary" @click="typeQuery()">查询</el-button>
					</div>
					<div style="float: right; width: auto;margin-right: 20px; margin-left: 20px;">
						<el-input v-model="typePage.queryCriteria.typeName" placeholder="请输入名称进行查询"></el-input>
					</div>
				</div>
			</div>
			 
			<div style="box-shadow: 0 1px 8px 0 rgba(0, 0, 0, 0.1);height: 60px;line-height: 60px; margin-top: 20px;">
				<div style="float: left; font-size: 30px; width: 60px; text-align: center; border-right: 2px solid #DCDDE0;">
					<i class="el-icon-s-grid"></i>
				</div>
				<font color="#72767B" style="margin-left: 20px;">数据列表</font>
				
				<div style="float: right; margin-right: 30px;">
					<el-button type="info" :disabled="typeIndexList.length ==0" @click="delType()">删除</el-button>
				</div>
				<div style="float: right; margin-right: 30px;">
					<el-button type="info" :disabled="typeIndexList.length ==0" @click="modifyType()">修改</el-button>
				</div>
				<div style="float: right; margin-right: 30px;">
					<el-button type="info" @click="addTypeVisible = true">新增</el-button>
				</div>
			</div>
			<div style="box-shadow: 0 1px 8px 0 rgba(0, 0, 0, 0.1);margin-top: 4px;">
				<el-table height="600px" :data="allType" border style="width: 100%" @select="getType" :row-style="typeFormStyle">
					<el-table-column align="center" type="selection" width="55"></el-table-column>
					<el-table-column align="center" prop="typeNumber" label="编号" width="180"></el-table-column>
					<el-table-column align="center" prop="typeName" label="分类名称" width="200"></el-table-column>
					<el-table-column align="center" prop="subclassName" label="上级分类" width="200"></el-table-column>
					<el-table-column align="center" prop="typeLevel" label="级别" width="180"></el-table-column>
					<el-table-column align="center" prop="typeUnit" label="单位" width="180"></el-table-column>
					<el-table-column align="center" prop="typeOrder" label="排序" width="180"></el-table-column>
					<el-table-column align="center" :formatter="formatterShow" prop="typeShow" label="显示"></el-table-column>
					
				</el-table>
			</div>
			<div style="text-align: center;">
				<el-pagination :page-count="typePageCount" @current-change="changTypePage" 
				:current-page="typePage.indexPage"  background layout="prev, pager, next"></el-pagination>
			</div>
		</el-dialog>
		
		<!-- 新增分弹出框 -->
		<el-dialog title="新增下级" :visible.sync="addTypeVisible">
			<el-form :model="typeAddModel" :rules="oneModelRules" ref="addModel" label-width="120px" class="demo-ruleForm">
				
				<el-form-item label="上级名称" prop="typeName">
					<el-select clearable size='mini' v-model="stateSubclass" placeholder="所属上级" autocomplete="off">
						<el-option v-for="item in subclassList" :label="item.subclassName" :value ="item.subclassId"></el-option>
					</el-select>
				</el-form-item>
				
				<el-form-item label="类别名称" prop="typeName">
					<el-input type="text" autosize v-model="typeAddModel.typeName"></el-input>
				</el-form-item>
				
				<el-form-item label="排序" prop="typeOrder">
					<el-input type="number" autosize v-model="typeAddModel.typeOrder"></el-input>
				</el-form-item>
				
				<el-form-item label="级别" prop="typeLevel">
					<el-input type="number" autosize v-model="typeAddModel.typeLevel"></el-input>
				</el-form-item>
				
				<el-form-item label="单位" prop="typeUnit">
					<el-input type="text" autosize v-model="typeAddModel.typeUnit"></el-input>
				</el-form-item>
				
				<el-form-item label="图标上传" prop="primaryCategoryIcon">
				<el-upload class="upload-demo" action="http://localhost/primary-category/upload"
					:on-success="uploadSuccess" :file-list="fileList" list-type="picture">
					<el-button size="small" type="primary">点击上传</el-button>
					<div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
				</el-upload>
				</el-form-item>
				
				<el-form-item label="鉴定图定义">
					<div v-for="(image, index) in imageParamList">
						<div style="float: left;">
							<el-input v-model="image.appraisalImageName" placeholder="正面"></el-input>
						</div>
						<el-select clearable v-model="image.appraisalImageState" autocomplete="off">
							<el-option label="必选" value ="1"></el-option>
							<el-option label="可选" value ="0"></el-option>
						</el-select>
						<font size="3" class="del_font" @click="delImage(index)">删除</font>
					</div>
					<font size="3" class="del_font" @click="addImage()">新增</font>
				</el-form-item>
				
				<el-form-item label="分类描述" prop="typeDesc">
					<el-input type="textarea" v-model="typeAddModel.typeDesc"></el-input>
				</el-form-item>
				
				<el-form-item label="是否显示" prop="typeShow">
					<el-radio v-model="radio" label="1">是</el-radio>
					<el-radio v-model="radio" label="0">否</el-radio>
				</el-form-item>
				
				<el-form-item>
					<el-button type="primary" @click="addTypeSubmit('typeAddModel')">确认</el-button>
					<el-button type="primary" @click="cancel()">取消</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
		
		<!-- 修改分类弹出框 -->
		<el-dialog title="新增下级" :visible.sync="modifyTypeVisible">
			<el-form :model="typeOneModel" :rules="oneModelRules" ref="addModel" label-width="120px" class="demo-ruleForm">
				
				<el-form-item  label="类别编号" prop="typeNumber">
					<el-input readonly type="text" autosize v-model="typeOneModel.typeNumber"></el-input>
				</el-form-item>
				
				<el-form-item label="上级名称" prop="typeName">
					<el-select clearable size='mini' v-model="stateSubclass" placeholder="所属上级" autocomplete="off">
						<el-option v-for="item in subclassList" :label="item.subclassName" :value ="item.subclassId"></el-option>
					</el-select>
				</el-form-item>
				
				<el-form-item label="类别名称" prop="typeName">
					<el-input type="text" autosize v-model="typeOneModel.typeName"></el-input>
				</el-form-item>
				
				<el-form-item label="排序" prop="typeOrder">
					<el-input type="number" autosize v-model="typeOneModel.typeOrder"></el-input>
				</el-form-item>
				
				<el-form-item label="级别" prop="typeLevel">
					<el-input type="number" autosize v-model="typeOneModel.typeLevel"></el-input>
				</el-form-item>
				
				<el-form-item label="单位" prop="typeUnit">
					<el-input type="text" autosize v-model="typeOneModel.typeUnit"></el-input>
				</el-form-item>
				
				<el-form-item label="图标上传" prop="primaryCategoryIcon">
				<el-upload class="upload-demo" action="http://localhost/primary-category/upload"
					:on-success="uploadSuccess" :file-list="fileList" list-type="picture">
					<el-button size="small" type="primary">点击上传</el-button>
					<div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
				</el-upload>
				</el-form-item>
				
				<el-form-item label="鉴定图定义">
					<div v-for="(image, index) in imageParamList">
						<div style="float: left;">
							<el-input v-model="image.appraisalImageName" placeholder="正面"></el-input>
						</div>
						<el-select clearable v-model="image.appraisalImageState" autocomplete="off">
							<el-option label="必选" value ="1"></el-option>
							<el-option label="可选" value ="0"></el-option>
						</el-select>
						<font size="3" class="del_font" @click="delImage(index)">删除</font>
					</div>
					<font size="3" class="del_font" @click="addImage()">新增</font>
				</el-form-item>
				
				<el-form-item label="分类描述" prop="typeDesc">
					<el-input type="textarea" v-model="typeOneModel.typeDesc"></el-input>
				</el-form-item>
				
				<el-form-item label="是否显示" prop="typeShow">
					<el-radio v-model="radio" label="1">是</el-radio>
					<el-radio v-model="radio" label="0">否</el-radio>
				</el-form-item>
				
				<el-form-item>
					<el-button type="primary" @click="modifyTypeSubmit('typeOneModel')">确认</el-button>
					<el-button type="primary" @click="cancel()">取消</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		name: 'Subclass',
		data() {
			return {
				delVisible: false,
				//三积类
				stateSubclass: null,
				subclassList: [],
				addTypeVisible: false,
				modifyTypeVisible: false,
				typePage: {
					indexPage: 1,
					pageSize: 3,
					queryCriteria: {
						subclassId: 0,
						typeName:null
					}
				},
				typePageCount: 1,
				allType: [],
				typeFormShow: false,
				typeIndexList: [],
				typeAddModel: {
					previousNumber: null,
					subclassId: null,
					subclassName: null,
					primaryCategoryId: null,
					primaryCategoryName: null,
					typeName: null,
					typeOrder: null,
					typeLevel: null,
					typeDesc: null,
					typeShow: null,
					typeUnit: null,
					typeIcon: null,
					iconName: null,
					imageParamList: []
				},
				typeOneModel: {
					typeId: null,
					typeNumber: null,
					subclassId: null,
					subclassName: null,
					primaryCategoryId: null,
					primaryCategoryName: null,
					typeName: null,
					typeOrder: null,
					typeLevel: null,
					typeDesc: null,
					typeShow: null,
					typeUnit: null,
					typeIcon: null,
					iconName: null,
					imageParamList: []
				},
				
				radio: '1',
				stateList: [],
				state: null,
				oneAppraisaImage: {
					appraisalImageName: null,
					appraisalImageState: null
				},
				addModel: {
					previousNumber: null,
					primaryCategoryId: 0,
					primaryCategoryName: null,
					subclassName: null,
					subclassIcon: null,
					subclassLevel: null,
					subclassOrder: null,
					subclassShow: null,
					subclassDesc: null,
					iconName: null,
					//鉴定图定义集合
					imageParamList: []
				},
				imageParamList: [],
				fileList: [],
				dialogFormVisible: false,
				dialogFormVisible1: false,
				oneModelRules: {},
				//修改数据
				oneModel: {
					subclassId: null,
					subclassNumber: null,
					primaryCategoryId: 0,
					primaryCategoryName: null,
					subclassName: null,
					subclassIcon: null,
					subclassLevel: null,
					subclassOrder: null,
					subclassShow: null,
					subclassDesc: null,
					iconName: null,
					//鉴定图定义集合
					imageParamList: []
				},
				//多选框
				indexList: [],
				allCategory:[],
				categoryPage: {
					indexPage: 1,
					pageSize: 3,
					queryCriteria: {
						primaryCategoryId: 0,
						subclassName:null
					}
				},
				pageCount: 1,
			}	
		},
		methods: {
			//改变颜色
			formStyle({row, index}) {
				if(row.subclassShow == 0) {
					return {color: "#909399"}
				}
			},
			typeFormStyle({row, index}) {
				if(row.typeShow == 0) {
					return {color: "#909399"}
				}
			},
			//新增下级
			addType(subclassId) {
				this.stateSubclass = subclassId;
				this.getSubclassList();
				this.addTypeVisible = true;
			},
			//新增下级确定
			addTypeSubmit() {
				for(let i of this.imageParamList) {
					if(i.appraisalImageName == null || i.appraisalImageState == null) {
						this.imageParamList.remove(i);
					}
				}
				this.typeAddModel.imageParamList = this.imageParamList;
				if(this.allType.length > 0) {
					this.typeAddModel.previousNumber = this.allType[0].typeNumber;
				}
				console.log("----------------------")
				for(let i of this.subclassList) {
					if(i.subclassId == this.stateSubclass) {
						this.typeAddModel.primaryCategoryId = i.primaryCategoryId;
						this.typeAddModel.primaryCategoryName = i.primaryCategoryName;
						this.typeAddModel.subclassId = i.subclassId;
						console.log(i)
						this.typeAddModel.subclassName = i.subclassName;
					}
				}
				//是否显示 	
				this.typeAddModel.typeShow = this.radio;
				console.log(this.typeAddModel)
				this.$http.post("/goods-type/add", this.typeAddModel).then(data => {
					if(data.data.code == 200) {
						this.addTypeVisible = false;
						this.indexTypePage();
						this.typeIndexList = [];
						this.$message.success(data.data.message);
						this.typeAddModel.previousNumber = null;
						this.typeAddModel.subclassId = null;
						this.typeAddModel.subclassName = null;
						this.typeAddModel.primaryCategoryId = null;
						this.typeAddModel.primaryCategoryName = null;
						this.typeAddModel.typeName = null;
						this.typeAddModel.typeOrder = null;
						this.typeAddModel.typeLevel = null;
						this.typeAddModel.typeDesc = null;
						this.typeAddModel.typeShow = null;
						this.typeAddModel.typeUnit = null;
						this.typeAddModel.typeIcon = null;
						this.typeAddModel.iconName = null;
						this.typeAddModel.imageParamList = [];
					}else {
						this.$message.error(data.data.message);
					}
				});
			},
			//查看下级
			showType(subclassId) {
				this.typePage.queryCriteria.subclassId = subclassId;
				this.stateSubclass = subclassId;
				this.indexTypePage();
				this.typeFormShow = true;
			},
			//修改
			modifyType() {
				this.stateSubclass = this.typeOneModel.subclassId;
				this.getSubclassList();
				this.modifyTypeVisible = true;
			},
			//修改确认
			modifyTypeSubmit() {
				for(let i of this.imageParamList) {
					if(i.appraisalImageName == null || i.appraisalImageState == null) {
						this.imageParamList.remove(i);
					}
				}
				this.typeOneModel.imageParamList = this.imageParamList;
				
				for(let i of this.subclassList) {
					console.log(i.subclassId)
					if(i.subclassId = this.stateSubclass) {
						this.typeOneModel.primaryCategoryId = i.primaryCategoryId;
						this.typeOneModel.primaryCategoryName = i.primaryCategoryName;
					}
				}
				//是否显示
				this.typeOneModel.typeShow = this.radio;
				this.$http.post("/goods-type/modify", this.typeOneModel).then(data => {
					if(data.data.code == 200) {
						this.modifyTypeVisible = false;
						this.$message.success(data.data.message);
						this.typeIndexList = [];
					}else {
						this.$message.error(data.data.message);
					}
				});
			},
			//删除
			delType() {
				console.log(this.typeIndexList)
				this.$http.post("/goods-type/delete", this.typeIndexList).then(data => {
					if(data.data.code == 200) {
						this.$message.success(data.data.message);
						this.indexTypePage();
						this.getCategoryId();
					}else if(data.data.code == 801) {
						this.allCategory = [];
					}
				})
			},
			changTypePage(page) {
				this.typePage.indexPage = page;
				this.indexTypePage();
			},
			
			typeQuery() {
				this.indexTypePage();
			},
			getType(list) {
				this.typeIndexList = [];
				this.typeOneModel = {};
				for(let c of list) {
					this.typeIndexList.push(c.typeId);
				}
				if(list.length == 1) {
					this.typeOneModel = list[0];
				}
			},
			
			//三级类查询
			indexTypePage() {
				if(this.typePage.queryCriteria.subclassId == '' | this.typePage.queryCriteria.subclassId == null | this.typePage.queryCriteria.subclassId == undefined) {
					this.typePage.queryCriteria.subclassId = 0;
				}
				console.log(this.typePage)
				this.$http.post("/goods-type/find", this.typePage).then(data => {
					if(data.data.code == 200) {
						this.allType = data.data.data.dtoList;
						console.log(this.allType);
					}else if(data.data.code == 801) {
						this.allType = [];
					}
					this.typePageCount = data.data.data.pageCount;
					this.typePage.indexPage = data.data.data.indexPage;
				});
				
			},
			getSubclassList() {
				this.$http.get("/goods-type/findAll").then(data => {
					if(data.data.code == 200) {
						
						this.subclassList = data.data.data;
						console.log("===============")
						console.log(this.subclassList)
					}else if(data.data.code == 801) {
						this.subclassList = [];
					}
				})
			},
			
			
			
			formatterShow(row) {
				if(row.subclassShow != null) {
					if(row.subclassShow == 1) {
					return '是';
					}else {
					return '否';
					}
				}
				
				if(row.typeShow != null) {
					if(row.typeShow == 1) {
					return '是';
				}else {
					return '否';
				}
				}
				
			},
			//获取大类名字
			getCategoryId() {
				this.$http.get("/goods-subclass/list").then(data => {
					if(data.data.code == 200) {
						this.stateList = data.data.data.primaryCategoryDtoList;
					}
				})
			},
			//删除鉴定图定义
			delImage(index) {
				this.imageParamList.splice(index, 1);
			},
			//添加鉴定图定义
			addImage(index) {
				this.imageParamList.push({
					appraisalImageName: null,
					appraisalImageState: null
				});
			},
			
			uploadSuccess(response, file, fileList) {
				this.oneModel.iconName = file.name;
				this.oneModel.subclassIcon = response.data;
				this.addModel.iconName = file.name;
				this.addModel.subclassIcon = response.data;
			},
			
			changPage(page) {
				this.categoryPage.indexPage = page;
				this.loadIndexPage();
			},
			getCategory(list, row) {
				this.indexList = [];
				this.oneModel = {};
				for(let c of list) {
					this.indexList.push(c.subclassId);
				}
				if(list.length == 1) {
					this.oneModel = list[0];
				}
				console.log(list[0])
			},
			//新增
			confirmAdd() {
				for(let i of this.imageParamList) {
					if(i.appraisalImageName == null || i.appraisalImageState == null) {
						this.imageParamList.remove(i);
					}
				}
				if(this.allCategory.length > 0) {
					this.addModel.previousNumber = this.allCategory[0].subclassNumber;
				}
				this.addModel.imageParamList = this.imageParamList;
				//大类及名字
				for(let c of this.stateList) {
					if(c.primaryCategoryId == this.state) {
						this.addModel.primaryCategoryId = this.state;
						this.addModel.primaryCategoryName = c.primaryCategoryName;
					}
				}
				//是否显示
				this.addModel.subclassShow = this.radio;
				this.$http.post("/goods-subclass/add", this.addModel).then(data => {
					if(data.data.code == 200) {
						this.dialogFormVisible1 = false;
						this.loadIndexPage();
						this.$message.success(data.data.message);
						//清空
						this.addModel.previousNumber = null;
						this.addModel.primaryCategoryId = 0;
						this.addModel.primaryCategoryName = null;
						this.addModel.subclassName = null;
						this.addModel.subclassIcon = null;
						this.addModel.subclassLevel = null;
						this.addModel.subclassOrder =  null;
						this.addModel.subclassShow = null;
						this.addModel.subclassDesc = null;
						this.addModel.iconName = null;
						//鉴定图定义集合
						this.addModel.imageParamList = [];
					}else {
						this.$message.error(data.data.message);
					}
				});
			},
			//修改
			modifyCategory() {
				if(this.oneModel == null | this.oneModel == '' | this.oneModel.subclassId == null | this.oneModel.subclassId == '') {
					this.$message.warning("请选择一项进行修改");
				}else {
					this.$http.get("/goods-subclass/find-appraisal/"+ this.oneModel.subclassId).then(data => {
						if(data.data.code == 200) {
							let a = data.data.data.imageDtoList;
							for(let i of a) {
								i.appraisalImageState = i.appraisalImageState+'';
							}
							this.imageParamList = a;
						}else {
							this.imageParamList = [];
						}
					})
					this.state = this.oneModel.primaryCategoryId;
					this.dialogFormVisible = true;
				}
			},
			//确认修改
			confirm(formName) {
				
				for(let i of this.imageParamList) {
					if(i.appraisalImageName == null || i.appraisalImageState == null) {
						this.imageParamList.remove(i);
					}
				}
				this.oneModel.imageParamList = this.imageParamList;
				//大类及名字
				for(let c of this.stateList) {
					if(c.primaryCategoryId == this.state) {
						this.oneModel.primaryCategoryId = this.state;
						this.oneModel.primaryCategoryName = c.primaryCategoryName;
					}
				}
				this.$http.post("/goods-subclass/modify", this.oneModel).then(data => {
					if(data.data.code == 200) {
						this.dialogFormVisible = false;
						this.$message.success(data.data.message);
					}else {
						this.$message.error(data.data.message);
					}
				});
					
			},
			//取消修改
			cancel() {
				this.dialogFormVisible = false;
				this.dialogFormVisible1 = false;
				this.addTypeVisible = false;
				this.modifyTypeVisible = false;
				this.$message.info("已取消操作");
			},
			//删除
			delCategory() {
				this.$http.post("/goods-type/findIndex", this.indexList).then(data => {
					if(data.data.code == 200) {
						this.delVisible = true;
					}else {
						this.deleteConfirm();
					}
				})
				
			},
			//删除确认
			deleteConfirm() {
				this.delVisible = false;
				this.$http.post("/goods-subclass/delete", this.indexList).then(data => {
					if(data.data.code == 200) {
						this.$message.success(data.data.message);
						this.loadIndexPage();
					}
				})
			},
			
			//模糊查询
			vagueQuery() {
					this.categoryPage.queryCriteria.primaryCategoryId = this.state;
					this.loadIndexPage();
			},
			
			loadIndexPage() {
				if(this.categoryPage.queryCriteria.primaryCategoryId == '' | this.categoryPage.queryCriteria.primaryCategoryId == null | this.categoryPage.queryCriteria.primaryCategoryId == undefined) {
					this.categoryPage.queryCriteria.primaryCategoryId = 0;
				}
				this.$http.post("/goods-subclass/find", this.categoryPage).then(data => {
					if(data.data.code == 200) {
						this.allCategory = data.data.data.dtoList;
					}else if(data.data.code == 801) {
						this.allCategory = [];
					}
					this.pageCount = data.data.data.pageCount;
					this.categoryPage.indexPage = data.data.data.indexPage;
				})
			}
		},
		created() {
			this.loadIndexPage(),
			this.getCategoryId(),
			this.getSubclassList()
			// this.indexTypePage()
		}
	}
</script>

<style>
	.del_font {
		cursor: pointer; 
		margin: 10px;
	}
	.del_font:hover {
		color: blue;
	}
</style>
